package pool;

import java.awt.Point;
import java.util.Iterator;

import gameObject.Bullet;

public class BulletPool 
{
	public static final int MAX_BULLETS = 50;
	private GameObjectPool<Bullet> _bullets;
	
	public BulletPool()
	{
		_bullets = new GameObjectPool<Bullet>();
		for(int i = 0 ; i < MAX_BULLETS; i++)
		{
			Bullet bulletToAdd = new Bullet();
			_bullets.addInactive(bulletToAdd);
		}
	}
	
	public Iterator<Bullet> iterator()
	{
		return _bullets.iterator();
	}

	public int size() {
		return _bullets.size();
	}
	
	/**
	 * Assume we don't need to add a bullet to screen if no more inactive
	 */
	public void addBullet(Point shipPosition, int shipAngle) 
	{
		if(_bullets.canAddActiveElement())
		{
			Bullet bulletToAdd = _bullets.removeInactive();
			bulletToAdd.activate(shipPosition, shipAngle);
			_bullets.addActive(bulletToAdd);
		}		
	}	
	
}
